'use strict';

module.exports = function(sequelize, DataTypes) {
    const ledgerTag = sequelize.define('LedgerTag', {
        id: {
            type: DataTypes.BIGINT(20).UNSIGNED,
            allowNull: false,
            autoIncrement: true,
            primaryKey: true,
            readonly: true
        },
        ledger_id: {
            type: DataTypes.BIGINT(20).UNSIGNED,
            allowNull: false,
            comment: '台账设备Id'
        },
        tag_id: {
            type: DataTypes.BIGINT(20).UNSIGNED,
            allowNull: false,
            comment: '标签Id'
        }
    }, {
        tableName: 'sophic_ledger_tag',
        underscored: true,
        indexes: [

        ],
        defaultScope: {
            attributes: ['id', 'ledger_id', 'tag_id']
        },

        classMethods: {

            //operationLog: true,

            associate: function(models) {
                ledgerTag.belongsTo(models.Ledger, {
                    constraints: false,
                })
            }
        }
    });

    return ledgerTag;
};